#include "modelindicator.h"
#include "stringutils.h"
#include "symbol.h"

#include <QString>
#include <QChar>
#include <QDebug>

namespace qrcode {

ModelIndicator::ModelIndicator()
    :mIndicator("")
{
    mModelIndicator.reserve(10);
    mModelIndicator.push_back(MODEL_INDICATOR_ECI);   //0:ECI
    mModelIndicator.push_back(MODEL_INDICATOR_NUM);   //1:数字
    mModelIndicator.push_back(MODEL_INDICATOR_AN);    //2:字母数字
    mModelIndicator.push_back(MODEL_INDICATOR_BYTE);  //3:8位字节
    mModelIndicator.push_back(MODEL_INDICATOR_HZ);    //4:中国汉字
    mModelIndicator.push_back(MODEL_INDICATOR_SA);    //5:结构链接
    mModelIndicator.push_back(TERM);                  //6:终止符（信息结尾）
}

bool ModelIndicator::AnalysisData(std::string inputStr)
{
    StringUtils *pStrUtils = new StringUtils();

    if(pStrUtils->ContainChinese(inputStr)){
        mIndicator = mModelIndicator.at(0);
        StringUtils::PRINT("模式：ECI");
        return true;
    } else if(pStrUtils->IsPureNumber(inputStr)){
        mIndicator = mModelIndicator.at(1);
        StringUtils::PRINT("模式：数字");
        return true;
    } else if(pStrUtils->IsAlphaNumber(inputStr)){
        mIndicator = mModelIndicator.at(2);
        StringUtils::PRINT("模式：字母数字");
        return true;
    } else if(pStrUtils->IsByte(inputStr)){
        mIndicator = mModelIndicator.at(3);
        StringUtils::PRINT("模式：8位字节");
        return true;
    } else {
        return false;
    }
}

std::string ModelIndicator::GetModelIndicator()
{
    if(mIndicator != "")
    {
        return mIndicator;
    } else {
        qDebug() << "没有确定模式指示符！！";
    }
}

}
